# Contributor: Leonardo Arena <rnalrd@alpinelinux.org>
# Maintainer: Leonardo Arena <rnalrd@alpinelinux.org>
pkgname=dkimproxy
pkgver=1.4.1
pkgrel=9
pkgdesc="SMTP-proxy that signs and/or verifies emails, using the Mail::DKIM module"
url="https://dkimproxy.sourceforge.net/"
arch="noarch"
license="GPL-2.0-or-later"
options="!check" # no testsuite
depends="perl-mail-dkim perl-net-server perl-error"
subpackages="$pkgname-doc $pkgname-openrc"
install="$pkgname.pre-install"
source="https://downloads.sourceforge.net/dkimproxy/dkimproxy-$pkgver.tar.gz
	dkimproxy_out.conf.patch
	dkimproxy.in.initd
	dkimproxy.out.initd
	dkimproxy.in.confd
	dkimproxy.out.confd
	"

build() {
	local vendorlib=$(perl -V:vendorlib | sed -En "s|vendorlib='([^']+)';|\1|p")

	perllibdir="$vendorlib" ./configure --prefix=/usr \
		--sysconfdir=/etc/$pkgname \
		--mandir=/usr/share/man \
		--infodir=/usr/share/info \
		--bindir=/usr/bin
	make
}

package() {
	make DESTDIR="$pkgdir" install

	cd "$pkgdir"

	mkdir -p ./usr/sbin
	mv ./usr/bin/$pkgname.* ./usr/sbin/
	mv ./usr/bin/dkim_responder.pl ./usr/bin/dkim_responder

	local path; for path in ./etc/$pkgname/*.example; do
		mv $path ${path%.example}
	done

	local name; for name in $pkgname.in $pkgname.out; do
		install -D -m 755 "$srcdir"/$name.initd ./etc/init.d/$name
		install -D -m 644 "$srcdir"/$name.confd ./etc/conf.d/$name
	done
}

sha512sums="ad5ac961ea25cdd7ccc763521d1fa5e143ef93056ca4bdace1d0d8f564ab85cb128b4c97ace310bcbf9e4d49430dd5baf1e9f836f5a44a4b3f1e7498ebc352b6  dkimproxy-1.4.1.tar.gz
b0573acb08f81e34a0e76819d48fe2fe08baa2a6f921e5927b8253ba4503f7b16bd43b57d4141d429db72cbf46b71566dfbdc6ea862e6fff58b90305e3a58147  dkimproxy_out.conf.patch
3b0032aa1187e75c890f573bcfc4f582648dca734286f50db2ea49caec8070d9a8b2dd6a9041c94e69bd2b89ad469296fb34cb6559f8d62c2579c687462f8dfa  dkimproxy.in.initd
fad58eff8c25b6c2ac711a82f94ec313ad8fbd4acadd3c2ee80be69dfca444de3aaf9e199d6e8cca58e0b977f4fa8e403f936f75e7f98545592ebc8ee1be3c53  dkimproxy.out.initd
d1e9a491b5c63b26c4d59a8dc79e6539e60f1e82f93911b0cd0384ea4200b2494ca5bff41f29c994b0f706d11bcf603504e532801c62f207c227a6040b057e89  dkimproxy.in.confd
27f7bec93906a2a8bda742afbed2cd972b36439c3241a89d20883c2c0a1ab340820055370e379daa9fe78e334f2723e8a48a99be504ddd2544c5f3356ec9578f  dkimproxy.out.confd"
